package com.zz.bid.mapper;

import com.zz.bid.pojo.query.SettleQuery;
import com.zz.bid.pojo.to.SettlementDesc;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SettleMapper {

    @Insert("insert into op_settle(name,settleMan,scale,valuation,signDate,lastUpdateUser,lastUpdateTime,createdBy,editMan,createdDate) "
            + "values(#{settle.name},#{settle.settleMan},#{settle.scale},#{settle.valuation},#{settle.signDate},#{settle.lastUpdateUser},#{settle.lastUpdateTime},#{settle.createdBy},#{settle.editMan},#{settle.createdDate}) ")
    @Options(useGeneratedKeys = true, keyProperty = "settle.id", keyColumn = "id")
    void addSettlement(@Param("settle") SettlementDesc settlementDesc);

    @Select("select id,name,inCharge,scale,valuation,signDate,createdBy from op_settle " + "where enable=1")
    SettlementDesc getSettle(@Param("settleId") Integer settleId);

    @Update("update op_settle set name=#{settle.name},settleMan=#{settle.settleMan},scale=#{settle.scale}, "
            + "valuation=#{settle.valuation},signDate=#{settle.signDate}, "
            + "lastUpdateUser=#{settle.lastUpdateUser},lastUpdateTime=#{settle.lastUpdateTime},editMan=#{settle.editMan} "
            + "where id=#{settle.id}")
    void update(@Param("settle") SettlementDesc settlementDesc);

    @Update("update op_settle set enable=0 where id=#{settleId}")
    void logicDelete(@Param("settleId") Integer settleId);

    @Update("update op_settle set " + "techMan=#{settle.techMan}," + "buildingStart=#{settle.buildingStart},"
            + "buildingEnd=#{settle.buildingEnd}," + "reportDate=#{settle.reportDate},"
            + "hasFirstReport=#{settle.hasFirstReport}," + "hasDetailReport=#{settle.hasDetailReport},"
            + "hasPicAudit=#{settle.hasPicAudit}," + "outsideReportEqual=#{settle.outsideReportEqual}, "
            + "hasBadWorkSign=#{settle.hasBadWorkSign}," + "hasOtherSign=#{settle.hasOtherSign}, "
            + "hasWitness=#{settle.hasWitness}, " + "printCost=#{settle.printCost}, " + "inCharge=#{settle.inCharge} "
            + "where id=#{settle.id} ")
    void updateForTechMan(@Param("settle") SettlementDesc settlementDesc);

    @Update("update op_settle set " + "firstArriveMoney=#{settle.firstArriveMoney},"
            + "firstArriveMoneyDate=#{settle.firstArriveMoneyDate}," + "secondArriveMoney=#{settle.secondArriveMoney},"
            + "secondArriveMoneyDate=#{settle.secondArriveMoneyDate}," + "thirdArriveMoney=#{settle.thirdArriveMoney},"
            + "thirdArriveMoneyDate=#{settle.thirdArriveMoneyDate}," + "finalDeposit=#{settle.finalDeposit},"
            + "firstLabor=#{settle.firstLabor}, " + "firstLaborDate=#{settle.firstLaborDate}, "
            + "secondLabor=#{settle.secondLabor}, " + "secondLaborDate=#{settle.secondLaborDate}, "
            + "thirdLabor=#{settle.thirdLabor}, " + "thirdLaborDate=#{settle.thirdLaborDate} " + "where id=#{settle.id}")
    void updateForCostMan(@Param("settle") SettlementDesc settlementDesc);

    List<SettlementDesc> getSettles(@Param("settleQuery") SettleQuery settleQuery);

}
